package com.hex.ds.hdtp.core.inf.data.table.repository.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.data.table.mapper.ITableTransferTaskMapper;
import com.hex.ds.hdtp.core.inf.data.table.po.TableTransferTaskPo;
import com.hex.ds.hdtp.core.inf.data.table.repository.ITableTransferTaskRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.inf.data.table.repository.impl
 * @ClassName TableTransferTaskRepository
 * @Description 表迁移任务-数据接口实现类
 * @Author Wang zhihao
 * @Date 2023/8/8 18:42
 * @Version v1.0
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TableTransferTaskRepository implements ITableTransferTaskRepository {

    private final ITableTransferTaskMapper tableTransferTaskMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /**
     * @Method queryListByPage
     * @Param
     * @param tableTransferTaskPo
     * @param toPage
     * @Return com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.data.table.po.TableTransferTaskPo>
     * @Description 分页查询
     * @Author Wang zhihao
     * @Date 2023/8/8 19:24
     * @Version V1.0
     */
    @Override
    public Page<TableTransferTaskPo> queryListByPage(TableTransferTaskPo tableTransferTaskPo, Page toPage) {
        final IPage tmpPageReslt = tableTransferTaskMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(toPage)
                , tableTransferTaskPo
        );
        final List list = tmpPageReslt.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageReslt);
        return pageResult.setData(list);
    }

    /**
     * @Method queryList
     * @Param
     * @param TableTransferTaskPo
     * @Return java.util.List<com.hex.ds.hdtp.core.inf.data.table.po.TableTransferListPo>
     * @Description 表迁移任务-不分页查询
     * @Author Wang zhihao
     * @Date 2023/8/10 18:29
     * @Version V1.0
     */
    @Override
    public List<TableTransferTaskPo> queryList(TableTransferTaskPo TableTransferTaskPo) {
        return tableTransferTaskMapper.queryList(TableTransferTaskPo);
    }

    /**
     * @Method addWithBackPkId
     * @Param
     * @param tableTransferTaskPo
     * @Return java.lang.String
     * @Description 新增任务并返回主键
     * @Author Wang zhihao
     * @Date 2023/8/9 16:19
     * @Version V1.0
     */
    @Override
    public String addWithBackPkId(TableTransferTaskPo tableTransferTaskPo) {
        tableTransferTaskPo.setTransferStatus("TODO");
        tableTransferTaskMapper.insert(tableTransferTaskPo);
        return tableTransferTaskPo.getPkId();
    }

    /**
     * @Method queryInfoById
     * @Param
     * @param pkId
     * @Return com.hex.ds.hdtp.core.inf.data.table.po.TableTransferTaskPo
     * @Description 根据主键获取建表任务信息
     * @Author Wang zhihao
     * @Date 2023/8/13 22:12
     * @Version V1.0
     */
    @Override
    public TableTransferTaskPo queryInfoById(String pkId) {
        return tableTransferTaskMapper.queryInfoById(pkId);
    }

    /**
     * @Method modifySuccessRunLog
     * @Param
     * @param pkId
     * @Return void
     * @Description 更新成功的表迁移数量
     * @Author Wang zhihao
     * @Date 2023/8/16 11:38
     * @Version V1.0
     */
    @Override
    public void modifySuccessNum(String pkId) {
        tableTransferTaskMapper.modifySuccessNum(pkId);
    }

    /**
     * @Method modifyFailRunLog
     * @Param
     * @param pkId
     * @Return void
     * @Description 更新失败的表迁移数量
     * @Author Wang zhihao
     * @Date 2023/8/16 11:38
     * @Version V1.0
     */
    @Override
    public void modifyFailNum(String pkId) {
        tableTransferTaskMapper.modifyFailNum(pkId);
    }

    /**
     * @Method modifyStatus
     * @Param
     * @Param endTime
     * @Param pkId
     * @Return void
     * @Description 更新表迁移任务状态
     * @Author gj.xu
     * @Date 2023/9/26 15:40
     * @Version V2.0
     */
    @Override
    public void modifyTransferStatus(String endTime, String pkId) {
        tableTransferTaskMapper.modifyTransferStatus(endTime, pkId);
    }

    /**
     * @Method increaseTotalNum
     * @Param
     * @param pkId
     * @Return void
     * @Description 增加清单总数
     * @Author Wang zhihao
     * @Date 2023/8/25 10:23
     * @Version V1.0
     */
    @Override
    public void increaseTotalNum(String pkId) {
        tableTransferTaskMapper.increaseTotalNum(pkId);
    }

    /**
     * @Method decreaseTotalNum
     * @Param
     * @param pkId
     * @Return void
     * @Description 减少清单总数
     * @Author Wang zhihao
     * @Date 2023/8/25 10:23
     * @Version V1.0
     */
    @Override
    public void decreaseTotalNum(String pkId) {
        tableTransferTaskMapper.decreaseTotalNum(pkId);
    }

    /**
     * @Method queryById
     * @Param
     * @param pkId
     * @Return com.hex.ds.hdtp.core.inf.data.table.po.TableTransferTaskPo
     * @Description 根据主键查询
     * @Author Wang zhihao
     * @Date 2023/8/8 19:55
     * @Version V1.0
     */
    @Override
    public TableTransferTaskPo queryById(String pkId) {
        return tableTransferTaskMapper.selectById(pkId);
    }

    /**
     * @Method add
     * @Param
     * @param tableTransferTaskPo
     * @Return java.lang.Integer
     * @Description 新增任务
     * @Author Wang zhihao
     * @Date 2023/8/8 19:55
     * @Version V1.0
     */
    @Override
    public Integer add(TableTransferTaskPo tableTransferTaskPo) {
        return tableTransferTaskMapper.insert(tableTransferTaskPo);
    }

    /**
     * @Method modifyById
     * @Param
     * @param tableTransferTaskPo
     * @Return java.lang.Integer
     * @Description 通过ID修改
     * @Author Wang zhihao
     * @Date 2023/8/8 19:55
     * @Version V1.0
     */
    @Override
    public Integer modifyById(TableTransferTaskPo tableTransferTaskPo) {
        return tableTransferTaskMapper.updateById(tableTransferTaskPo);
    }

    /**
     * @Method removeById
     * @Param
     * @param pkId
     * @Return java.lang.Integer
     * @Description 通过主键删除
     * @Author Wang zhihao
     * @Date 2023/8/8 19:56
     * @Version V1.0
     */
    @Override
    public Integer removeById(String pkId) {
        return tableTransferTaskMapper.deleteById(pkId);
    }

}
